package cn.iocoder.yudao.module.system.service.agent;

import cn.iocoder.yudao.framework.common.enums.RequestUriEnum;
import com.ffcs.ebp.ebpsdk.YunSign;
import com.ffcs.ebp.ebpsdk.common.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

/**
 * 请求API服务类
 */
@Slf4j
@Service
public class RequestService {



    @Value("${apiproxy.serverName}")
    private String serverName;

    @Value("${apiproxy.ak}")
    private String ak;

    @Value("${apiproxy.sk}")
    private String sk;






    public Response getResponse(RequestUriEnum uri, Map<String,Object> headerMap, String body, String queryStr) {
        //0:绕过ssl证书   1：验证ssl证书
        int temp = uri.getTemp();
        //ctyun-eop-request-id(32位uuid)
        String uuId = UUID.randomUUID().toString();
        uuId = uuId.replaceAll("\\-", "");
        YunSign yunSign = new YunSign(serverName+uri.getUri(), ak, sk, uuId, body, temp, uri.getContentType(), queryStr, headerMap);
        Response response = yunSign.toDo(uri.getMethod().name());
        return response;
    }
}
